{minimum_otp_vsn, "21.0"}.
{compiler_error_format, rich}.

{deps,
 [{conf, "~> 0.1"},
  {stun, "~> 1.2"},
  {influx_udp, "~> 1.1.1"},
  {prometheus_httpd, "~> 2.1"},
  recon]}.

{relx,
 [{release, {eturnal, {cmd, "tools/get-version"}},
   [eturnal,
    sasl,
    recon,
    % For mod_stats_influx:
    {influx_udp, none},
    {poolboy, none},
    {ulitos, none},
    % For mod_stats_prometheus:
    {prometheus_httpd, none},
    {prometheus, none},
    {accept, none},
    {inets, none},
    {ssl, none}]},
  % We don't use {mode, dev}: https://github.com/erlang/rebar3/issues/2598
  {dev_mode, false}, % See: https://github.com/erlang/rebar3/issues/2739
  {debug_info, keep},
  {include_erts, false},
  {include_src, true},
  {src_tests, false},
  {sys_config, "config/sys.config"},
  {vm_args, "config/vm.args"},
  {extended_start_script_hooks,
   [{pre_start,
     [{custom, "hooks/pre_start"}]},
    {post_start,
     [{wait_for_process, eturnal}]}]},
  {extended_start_script_extensions,
   [{credentials, "extensions/credentials"},
    {disconnect, "extensions/disconnect"},
    {info, "extensions/info"},
    {loglevel, "extensions/loglevel"},
    {password, "extensions/password"},
    {reload, "extensions/reload"},
    {sessions, "extensions/sessions"},
    {version, "extensions/version"}]},
  {overlay_vars, "build.config"},
  {overlay,
   [{copy, "LICENSE", "doc/LICENSE.txt"},
    {copy, "CHANGELOG.md", "doc/CHANGELOG.md"},
    {copy, "README.md", "doc/README.md"},
    {copy, "config/eturnal.yml", "etc/eturnal.yml"},
    {copy, "overlay/extensions/credentials", "bin/extensions/credentials"},
    {copy, "overlay/extensions/disconnect", "bin/extensions/disconnect"},
    {copy, "overlay/extensions/info", "bin/extensions/info"},
    {copy, "overlay/extensions/loglevel", "bin/extensions/loglevel"},
    {copy, "overlay/extensions/password", "bin/extensions/password"},
    {copy, "overlay/extensions/reload", "bin/extensions/reload"},
    {copy, "overlay/extensions/sessions", "bin/extensions/sessions"},
    {copy, "overlay/hooks/post_stop", "bin/hooks/post_stop"},
    {copy, "overlay/hooks/pre_start", "bin/hooks/pre_start"},
    {copy, "overlay/init/openrc/eturnal.confd", "etc/openrc/eturnal.confd"},
    {copy, "overlay/logrotate/eturnal", "etc/logrotate.d/eturnal"},
    {template, "overlay/eturnalctl", "bin/eturnalctl"},
    {template, "overlay/extensions/version", "bin/extensions/version"},
    {template, "overlay/init/openrc/eturnal.initd", "etc/openrc/eturnal.initd"},
    {template, "overlay/init/sysv/eturnal", "etc/init.d/eturnal"},
    {template, "overlay/init/systemd/eturnal.service", "etc/systemd/system/eturnal.service"}]}]}.

{erl_opts,
 [{platform_define, "^21\.[0-2]\.", old_persistent_term},
  {platform_define, "^21\.[0-2]\.", old_logger},
  {platform_define, "^2[123]\.", old_rand},
  {platform_define, "^2[12]\.", old_atom_conversion},
  {platform_define, "^2[12]\.", old_crypto},
  {platform_define, "^2[12]\.", old_inet_backend},
  {platform_define, "win32", old_inet_backend},
  warn_export_vars,
  warn_missing_spec_all,
  warn_unused_import,
  warnings_as_errors,
  debug_info]}.

{dialyzer,
 [{warnings,
   [unknown,
    unmatched_returns,
    error_handling]},
  {plt_extra_apps, % Nested dependencies which we call directly.
   [fast_tls,
    yval,
    % For mod_stats_influx:
    influx_udp,
    % For mod_stats_prometheus:
    inets,
    prometheus,
    prometheus_httpd]}]}.

{xref_checks,
 [undefined_function_calls,
  undefined_functions,
  deprecated_function_calls,
  deprecated_functions,
  locals_not_used]}.

{ct_opts,
 [{keep_logs, 10},
  {config,
   ["test/eturnal_SUITE.config"]}]}.

{cover_enabled, true}.

{cover_excl_mods,
 [eturnal_systemd]}.

{cover_opts,
 [verbose,
  {min_coverage, 50}]}.

{elvis,
 [#{dirs => ["src"],
    filter => "*.erl",
    ruleset => erl_files,
    rules =>
     [{elvis_style, no_import, disable},
      {elvis_style, no_if_expression, disable},
      {elvis_style, no_catch_expressions, #{ignore => [{eturnal, log_control_listener}]}},
      {elvis_style, no_spec_with_records, #{ignore => [eturnal_cert]}},
      {elvis_style, atom_naming_convention, #{ignore => [eturnal_cert]}},
      {elvis_style, export_used_types, #{ignore => [eturnal_misc]}},
      {elvis_style, macro_names, #{ignore => [eturnal_module]}},
      {elvis_text_style, line_length, #{limit => 80}}]},
  #{dirs => ["."],
    filter => "rebar.config",
    ruleset => rebar_config,
    rules =>
     [{elvis_project, no_branch_deps, disable}]}]}.

{edoc_opts,
 [{preprocess, true}]}.

{shell,
 [{config, "config/shell.config"}]}.

{profiles,
  % Production release:
 [{prod,
   [{relx,
     [{dev_mode, false},
      {debug_info, strip},
      {system_libs, true},
      {include_erts, true},
      {include_src, false},
      {overlay,
       [{template, "client/stun", "bin/stun"}]},
      {exclude_apps,
       [compiler,                 % Unused 'p1_utils' dependency.
        quantile_estimator]}]},   % Unused 'prometheus' dependency.
    {erl_opts,
     [no_debug_info,
      deterministic]}]},
  % Distribution packaging:
  {distro,
   [{relx,
     [{release, {eturnal, {cmd, "tools/get-version"}},
       [eturnal]},
      {mode, minimal},
      {system_libs, false}]},
    {erl_opts,
     [no_debug_info,
      deterministic]}]},
  % Running the test suite:
  {test,
   [{erl_opts,
     [nowarn_export_all,
      nowarn_missing_spec_all]}]},
  % Building documentation with ExDoc rather than EDoc:
  {exdoc,
   [{edoc_opts,
     [{doclet, edoc_doclet_chunks},
      {layout, edoc_layout_chunks},
      {dir, "_build/exdoc+docs/lib/eturnal/doc"}]},
    {post_hooks,
     [{edoc, "ex_doc eturnal $(tools/get-version) \\
              \"$REBAR_BUILD_DIR/lib/eturnal/ebin\" \\
              --paths '_build/default/lib/*/ebin' \\
              --source-ref $(git describe --tags) \\
              --config 'config/doc.config'"}]}]}]}.

{overrides,
 [{add, quantile_estimator,
   [{erl_opts,
     [{no_auto_import, [{ceil, 1}, {floor, 1}]}]}]},
  {del, stun,
   [{erl_opts, % Let 'stun' use the new logging API on Erlang/OTP 21 as well.
     [{platform_define, "^(R|1|20|21)", 'USE_OLD_LOGGER'}]}]},
  % The rebar3_archive_plugin (used by prometheus_httpd and accept) depends on
  % the rebar3_elvis_plugin, which conflicts with rebar3_lint.
  {del,
   [{plugins, [{rebar3_archive_plugin, "0.0.1"}]},
    {plugins, [{rebar3_archive_plugin, "0.0.2"}]}]}]}.

{pre_hooks,
 [{clean, "rm -f client/stun"},
  {release, "escript client/build client/stun"},
  {release, "chmod o-rw config/eturnal.yml"},
  {tar, "escript client/build client/stun"},
  {tar, "chmod o-rw config/eturnal.yml"}]}.

{plugins,
 [rebar3_lint]}.

{alias,
 [{check,
   [xref,
    dialyzer,
    ct,
    eunit,
    cover,
    lint]},
  {bump,
   [update,
    {clean, "-a"},
    {upgrade, "-a"}]}]}.
